<?php 
/*
 module:		会员充值订单
 create_time:	2022-04-05 20:59:05
 author:		
 contact:		
*/

namespace app\api\service;
use app\api\model\ZhMatchmakerOrder;
use think\facade\Log;
use think\exception\ValidateException;
use xhadmin\CommonService;

class ZhMatchmakerOrderService extends CommonService {

    /*
        * @Description  列表数据
        */
    public static function indexList($where, $limit, $page)
    {
        try {
            $res = \app\backend\model\ZhMatchmakerOrder::alias('o')
//                ->leftjoin('zh_matchmaker ','o.m_id=zh_matchmaker.matchmaker_id')
//                ->leftjoin('zh_authentication ','o.a_id=zh_authentication.authentication_id')
                ->leftjoin('zh_matchmaker_charge','o.c_id=zh_matchmaker_charge.id')
                ->leftjoin('zh_matchmaker_cash','o.id=zh_matchmaker_cash.o_id')
                /*   ->leftjoin('member m','zh_matchmaker.u_id = m.uid')
                   ->leftjoin('member a','zh_authentication.u_id = a.uid')*/
                ->where($where)
//                ->field("o.id,o.m_id,o.a_id,o.price,o.status,o.order_sn,o.price,o.createtime,zh_authentication.real_name,zh_matchmaker.name,
//                 zh_matchmaker_charge.entry_name,zh_matchmaker_charge.comment,zh_matchmaker_charge.is_fixed_price")
                ->field("o.id,o.m_id,o.a_id,o.price,o.status,o.order_sn,o.price,o.createtime,o.updatetime,
                 zh_matchmaker_charge.entry_name,zh_matchmaker_charge.comment,zh_matchmaker_charge.is_fixed_price,zh_matchmaker_cash.price as cash_price")
                ->order(['createtime' => 'desc'])
                ->paginate(['list_rows'=>$limit,'page'=>$page])
                ->toArray();

        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        return ['rows' => $res['data'], 'total' => $res['total']];
    }

	/*
 	* @Description  添加
 	*/
	public static function add($data){
		try{
			$data['status'] = !is_null($data['status']) ? $data['status'] : '0';
			$data['createtime'] = time();
			$res = ZhMatchmakerOrder::create($data);
		}catch(ValidateException $e){
			throw new ValidateException ($e->getError());
		}catch(\Exception $e){
			abort(config('my.error_log_code'),$e->getMessage());
		}
		return $res->id;
	}




}

